package com.tarena.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tarena.bo.UserDao;
import com.tarena.controller.Action;
import com.tarena.util.FormUtils;
import com.tarena.vo.User;

/**
 * @登录验证类
 * @author WangPeihu
 * @since 31/12/2009
 * @Team [Never give up]
 * 
 */
public class LoginAction extends Action {
	private UserDao ud = new UserDao();

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		try {
			User user = new User();
			FormUtils.populate(user, request);
			if (ud.validateUser(user)) {
				HttpSession session = request.getSession();
				session.setAttribute("user_key", user);
				response.sendRedirect("emp_list");
			} else {
				response.sendRedirect("login_form");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
